<template>
	<view class="content">
		<view class="radio_s">
			<view class="radio" :class="{'radio_c':type==1}" @click="type=1">
				<uni-icons v-if="type==1" type="checkbox" color="#ffffff" size="24" class="icon"></uni-icons>
				<uni-icons v-else type="circle" color="#dddddd" size="24" class="icon"></uni-icons>
				<view>待还本金</view>
				<view :class="{'col_red':type!=1}">￥{{loan_money}}</view>
			</view>
			<view class="radio" :class="{'radio_c':type==2}" @click="type=2">
				<uni-icons v-if="type==2" type="checkbox" color="#ffffff" size="24" class="icon"></uni-icons>
				<uni-icons v-else type="circle" color="#dddddd" size="24" class="icon"></uni-icons>
				<view>待还利息</view>
				<view :class="{'col_red':type!=2}">￥{{company_interest}}</view>
			</view>
		</view>
		<view class="info">
			<view class="item">
				<image src="@/static/img/topup_1.png" mode="widthFix"></image>
				<view class="i_title">充值方式</view>
				<view>线下支付</view>
			</view>
			<view class="item bor_no">
				<image src="@/static/img/topup_2.png" mode="widthFix"></image>
				<view class="i_title">充值金额</view>
			</view>
			<view class="money">
				<text>￥</text>
				<input type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="pla_css" />
			</view>
			<!-- <view class="item">
				<image src="@/static/img/topup_3.png" mode="widthFix"></image>
				<view class="i_title">充值费用</view>
				<view>10000.00元</view>
			</view>
			<view class="item">
				<image src="@/static/img/topup_4.png" mode="widthFix"></image>
				<view class="i_title">实付金额</view>
				<view>10000.00元</view>
			</view> -->
			<view class="item bor_no">
				<image src="@/static/img/topup_5.png" mode="widthFix"></image>
				<view class="i_title">上传凭证</view>
			</view>
			<uni-file-picker limit="1" v-model="ercode_img" @select="select"></uni-file-picker>
			<view class="item bor_no">
				<image src="@/static/img/topup_6.png" mode="widthFix"></image>
				<view class="i_title">银行流水号</view>
			</view>
			<input type="text" class="liu" v-model="sn" placeholder="请输入银行流水号" />
			<view class="item bor_no">
				<image src="@/static/img/topup_7.png" mode="widthFix"></image>
				<view class="i_title">充值银行</view>
			</view>
			<view class="card" v-for="item in list">
				<image class="cardimg" :src="item.img" mode="widthFix"></image>
				<view>{{item.zhi_name}}</view>
				<view>{{item.card_num}}</view>
			</view>
			<!-- <image class="cardimg" src="@/static/img/topup_card1.png" mode="widthFix"></image>
			<image class="cardimg" src="@/static/img/topup_card2.png" mode="widthFix"></image>
			<image class="cardimg" src="@/static/img/topup_card3.png" mode="widthFix"></image> -->
		</view>
		<view class="default_btn btn" @click="confirm">确定充值</view>
	</view>
</template>

<script>
	import {
		topUp,
		uploadImg,
		fileUp,
		cardInfo
	} from '@/common/js/index.js'
	export default {
		data() {
			return {
				money: '',
				sn: '',
				img: '',
				ercode_img: {},
				list: '',
				daihuan: true,
				company_interest: '',
				loan_money: '',
				type: 1,	//1本金 2利息
			}
		},
		onLoad() {
			this.card()
		},
		methods: {
			card() {
				cardInfo().then(res => {
					this.list = res.data.list
					this.company_interest = res.data.company_interest
					this.loan_money = res.data.loan_money
					console.log(res);
				})
			},
			select(e) {
				console.log('选择文件：', e)
				// var file = e.tempFiles
				var file = e.tempFilePaths[0]
				fileUp({
					file: file
				}).then(res => {
					console.log(res);
					var info = JSON.parse(res)
					if (info.code == 200) {
						this.img = info.data[0]
						console.log(this.img);
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 3000
						})
					}
				})
			},
			confirm() {
				console.log(this.img);
				var hint
				if (!this.money) {
					hint = '请输入充值金额'
				} else if (!hint && !this.img) {
					hint = '请上传凭证'
				} else if (!hint && !this.sn) {
					hint = '请输入银行流水号'
				}
				if (hint) {
					uni.showToast({
						title: hint,
						icon: 'none',
						duration: 3000
					})
					return
				}
				topUp({
					money: this.money,
					outer_notice_sn: this.sn,
					imgurl: this.img,
					type: this.type
				}).then(res => {
					console.log(res);
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 200) {
						this.money = ''
						this.sn = ''
						this.ercode_img = {
							url: ''
						}
						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					}
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.content {
		/* background: white; */
		position: relative;
		overflow: hidden;
	}
	
	.radio_s {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 40rpx 30rpx;
		.radio {
			width: 330rpx;
			height: 144rpx;
			position: relative;
			background: #FFFFFF;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			text-align: center;
			view:nth-of-type(1) {
				margin: 24rpx auto 16rpx;
			}
		}
		.radio_c {
			background: linear-gradient( 135deg, #F79862 0%, #FD7A6A 100%);
			color: white;
			view:nth-of-type(1) {
				font-weight: 500;
			}
			view:nth-of-type(2) {
				font-weight: 700;
			}
		}
		.icon {
			
			position: absolute;
			top: 12rpx;
			left: 12rpx;
		}
		.col_red {
			color: #F93D33;
		}
	}

	.info {
		margin: 40rpx 30rpx 80rpx;
		padding: 0 30rpx 40rpx;
		background-color: white;
		border-radius: 12rpx;

		.item {
			height: 110rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 2rpx solid #EEEEEE;

			.i_title {
				flex: 1;
			}

			image {
				width: 48rpx;
				margin-right: 20rpx;
			}
		}

		.money {
			border-bottom: 2rpx solid #CCCCCC;
			display: flex;
			padding-bottom: 20rpx;

			input {
				height: 70rpx;
				font-size: 48rpx;
				font-weight: 500;
				// background-color: pink;
			}

			text {
				position: relative;
				top: 14rpx;
				font-size: 26rpx;
				font-weight: 500;
			}

			.pla_css {
				font-size: 30rpx;
			}
		}

		.liu {
			width: 600rpx;
			height: 80rpx;
			background: #F7F7F7;
			border-radius: 8rpx;
			font-size: 26rpx;
			padding-left: 30rpx;
		}

		.card {
			width: 630rpx;
			height: 236rpx;
			position: relative;
			z-index: 777;
			overflow: hidden;
			margin-bottom: 30rpx;

			image {
				width: 630rpx;
				position: absolute;
				left: 0;
				top: 0;
				z-index: 888;
			}

			view {
				position: relative;
				color: white;
				z-index: 999;

				&:nth-of-type(1) {
					font-weight: 500;
					font-size: 34rpx;
					margin: 54rpx 0 0 144rpx;
				}

				&:nth-of-type(2) {
					font-weight: 500;
					font-size: 44rpx;
					margin: 58rpx 0 0 44rpx;
				}
			}
		}

		// .cardimg {
		// 	width: 630rpx;
		// 	margin-bottom: 30rpx;
		// 	display: block;
		// }
	}

	.btn {
		margin-bottom: 100rpx;
	}

	.bor_no {
		border: none !important;
	}
</style>